{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2024 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{% if must_change_password is defined and must_change_password %}
    <div class="alert alert-warning">
        <div class="alert-title">{{ __('Your password has expired. You must change it to be able to login.') }}</div>
    </div>
{% endif %}
{% if token_ok is defined and token_ok == false %}
    {{ __('Your password reset request has expired or is invalid. Please renew it.') }}
{% elseif messages_only is defined %}
    {{ include('components/messages_after_redirect_alerts.html.twig') }}
{% else %}
    <form action="{{ target }}" method="post" autocomplete="off" data-submit-once>
        <input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
        <h2 class="card-title text-center mb-4">{{ title }}</h2>

        {% if type == 'update' %}
            {% import 'components/form/fields_macros.html.twig' as fields %}
            {{ fields.textField('name', session('glpiname'), __('Login'), {
                readonly: true,
                full_width: true,
                additional_attributes: {
                    autocomplete: 'off',
                }
            }) }}
            {{ fields.passwordField('current_password', '', __('Current password'), {
                full_width: true,
                clearable: false,
                required: true,
                additional_attributes: {
                    autocomplete: 'current-password',
                }
            }) }}
        {% endif %}
        {% if token is defined or type == 'update' %}
            <input type="hidden" name="password_forget_token" value="{{ token }}" />
            {{ fields.passwordField('password', '', __('New password'), {
                full_width: true,
                clearable: false,
                required: true,
                additional_attributes: {
                    onkeyup: "passwordCheck();",
                    autocomplete: 'new-password',
                }
            }) }}
            {{ fields.passwordField('password2', '', __('New password confirmation'), {
                full_width: true,
                clearable: false,
                required: true,
                additional_attributes: {
                    onkeyup: "passwordCheck();",
                    autocomplete: 'new-password',
                }
            }) }}

            {% if config('use_password_security') %}
                <div class="alert alert-warning">
                    <h3>{{ __('Password security policy') }}</h3>
                    {{ include('components/user/password_security_checks.html.twig') }}
                </div>
            {% else %}
                <script>
                    function passwordCheck() {
                        return true;
                    }
                </script>
            {% endif %}

            {% set save_button = '<i class="ti ti-device-floppy"></i><span>' ~ __('Save new password') ~ '<span>' %}

        {% elseif type == 'forget' %}
            <p class="text-muted mb-4">
                {{ __('Please enter your email address. An email will be sent to you and you will be able to choose a new password.') }}
            </p>
            <div class="mb-3">
                {{ fields.emailField('email', '', _n('Email', 'Emails', 1), {
                    full_width: true,
                    required: true,
                }) }}
            </div>
            {% set save_button = '<i class="ti ti-mail"></i><span>' ~ __('Send') ~ '<span>' %}
        {% endif %}

        <div class="form-footer d-flex flex-row-reverse">
            <button class="btn btn-primary" name="update">
                {{ save_button|raw }}
            </button>
        </div>

        {% if errors is defined and errors|length > 0 %}
            <div class="alert alert-danger mt-2">
                {% for error in errors %}
                    <br>{{ error }}
                {% endfor %}
            </div>
        {% endif %}
    </form>
{% endif %}

